# -*- coding: UTF-8 -*-

from odoorpc2 import RPC

base_url = 'http://192.168.56.114:8069'

timeout = 50000

addons_list = ['odoorpc2/addons']


dbname = 'T1'
dbname = 'T2'
username = 'admin'
password = '123456'

rpc = RPC(base_url, timeout, dbname, addons_list)


def test_create():
    print('test_create')
    action_id = 'base.action_partner_category_form'
    form = rpc.env.formview(action_id)
    form.load_fields()

    res = form.onchange_new()
    print('res', res)
    record = {}
    values = {}
    record.update(res['record'])
    values.update(res['values'])

    print('record=', record)
    print('values=', values)

    res = form.onchange('name', 'test22')
    print('after name edit:', res)

    record.update(res['record'])
    values.update(res['values'])

    print('record=', record)
    print('values=', values)

    res_id = form.commit()
    print('after commit:', res_id)

    res = form.read(res_id)
    print('after read:', res)


def test():
    res = rpc.login(username,  password)

    test_create()


test()
